import 'package:flutter/material.dart';
import 'package:kasax/utils/log_utils.dart';

/// Anim的基本使用
/// 点击放大
class AnimHomeWidget extends StatefulWidget {
  const AnimHomeWidget({Key? key}) : super(key: key);

  @override
  _AnimHomeWidgetState createState() => _AnimHomeWidgetState();
}

class _AnimHomeWidgetState extends State<AnimHomeWidget> with SingleTickerProviderStateMixin {
  double size = 100;
  late AnimationController _animationController;

  @override
  void initState() {
    super.initState();
    // 动画时长:1000ms
    ///  this.lowerBound = 0.0,this.upperBound = 1.0, 最小值和最大值设定
    _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 1000));
    _animationController.addListener(() {
      var animValue = _animationController.value;
      LogUtil.e(animValue);
      setState(() {
        if (size < 200) {
          size += size * _animationController.value;
        }
      });
    });
    _animationController.addStatusListener((status) {});
  }

  @override
  void dispose() {
    super.dispose();
    _animationController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          Text(
            "点击下面区域，执行动画",
            style: Theme.of(context).textTheme.headline6,
          ),
          Expanded(
              child: GestureDetector(
            onTap: () {
              _animationController.forward();
            },
            child: Center(
              child: Container(
                color: Colors.green,
                width: size,
                height: size,
              ),
            ),
          ))
        ],
      ),
    );
  }
}
